<template>
  <div class="content">
    <card-view mb-10px title="基本信息">
      <template v-slot:end>
        <el-button type="primary" @click="backAction">返回</el-button>
      </template>
      <el-form
        ref="basicFormRef"
        :model="sheetDetails"
        label-position="top"
        inline
      >
        <el-form-item label="订单编号">
          <div class="form-view-item">{{ sheetDetails.codeNo }}</div>
        </el-form-item>
        <el-form-item label="生产组织">
          <div class="form-view-item">
            {{ blankAttributeDefault(sheetDetails.productionOrganizationName) }}
          </div>
        </el-form-item>
        <el-form-item label="生产车间">
          <div class="form-view-item">
            {{ blankAttributeDefault(sheetDetails.workshopName) }}
          </div>
        </el-form-item>
        <el-form-item label="生产人员">
          <div class="form-view-item">
            {{ blankAttributeDefault(sheetDetails.productionUserName) }}
          </div>
        </el-form-item>
        <el-form-item label="单据状态">
          <div class="form-view-item">
            <dict-tag :options="data_status" :value="sheetDetails.dataStatus" />
          </div>
        </el-form-item>
        <el-form-item label="业务日期">
          <div class="form-view-item">
            {{ blankAttributeDefault(sheetDetails.businessDate) }}
          </div>
        </el-form-item>
        <el-form-item label="工序计划单编号">
          <div class="form-view-item">
            {{ blankAttributeDefault(sheetDetails.planCodeNo) }}
          </div>
        </el-form-item>
        <el-form-item label="工序任务单编号">
          <div class="form-view-item">
            {{ blankAttributeDefault(sheetDetails.taskCodeNo) }}
          </div>
        </el-form-item>
        <el-form-item label="备注">
          <div class="form-view-item">
            {{ blankAttributeDefault(sheetDetails.remark) }}
          </div>
        </el-form-item>
      </el-form>
    </card-view>
    <card-view mb-10px title="用料清单">
      <el-table :data="tableList" border>
        <el-table-column label="序号" align="center" width="80">
          <template #default="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="产品编码" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.matterFullCode) }}
          </template>
        </el-table-column>
        <el-table-column label="产品名称" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.matterName) }}
          </template>
        </el-table-column>
        <el-table-column label="助记码" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.matterMnemonicCode) }}
          </template>
        </el-table-column>
        <el-table-column label="规格型号" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.matterSpecModel) }}
          </template>
        </el-table-column>
        <el-table-column label="表面" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.surfaceName) }}
          </template>
        </el-table-column>
        <el-table-column label="材质" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.matterMaterialQuality) }}
          </template>
        </el-table-column>
        <el-table-column label="批号" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.lotNumber) }}
          </template>
        </el-table-column>
        <el-table-column label="单轨长度(mm)" align="center" width="180">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.monorailLength) }}
          </template>
        </el-table-column>
        <el-table-column label="滑块数量" align="center" width="180">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.sliderNum) }}
          </template>
        </el-table-column>
        <el-table-column label="滑块总数量" align="center" width="180">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.sliderAllNum) }}
          </template>
        </el-table-column>
        <el-table-column label="导轨销售总长度(mm)" align="center" width="180">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.monorailAllLength) }}
          </template>
        </el-table-column>
        <el-table-column label="数量" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.receiveNums) }}
          </template>
        </el-table-column>
        <el-table-column label="计量单位" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.unitName) }}
          </template>
        </el-table-column>
        <el-table-column label="辅助数量" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.assistNums) }}
          </template>
        </el-table-column>
        <el-table-column label="辅助单位" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.assistUnitName) }}
          </template>
        </el-table-column>
        <el-table-column label="库存组织" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.stockOrganizationName) }}
          </template>
        </el-table-column>
        <el-table-column label="仓库" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.warehouse) }}
          </template>
        </el-table-column>
        <el-table-column label="仓位" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.position) }}
          </template>
        </el-table-column>
        <el-table-column label="领料人" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.receiveUserName) }}
          </template>
        </el-table-column>
        <el-table-column label="实际成本" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.actualCost) }}
          </template>
        </el-table-column>
        <el-table-column label="退货数量" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.returnNums) }}
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" width="150">
          <template #default="scope">
            {{ blankAttributeDefault(scope.row.remark) }}
          </template>
        </el-table-column>
      </el-table>
    </card-view>
    <card-view mb-10px title="制单信息">
      <document-view :list="documentList" />
    </card-view>
  </div>
</template>
<script setup>
import CardView from "@/components/CardView/index.vue";
import DocumentView from "@/components/DocumentView/index.vue";
import DictTag from "@/components/DictTag/index.vue";
import { blankAttributeDefault } from "@/utils/index";

import defineStore from "@/store/modules/dict";

import { detailsProductionMaterialRequisitionWithIdApi } from "@/api/details";
import { useRouter } from "vue-router";

const { proxy } = getCurrentInstance();
const { data_status } = toRefs(proxy?.useDict("data_status"));
const route = useRoute();
const router = useRouter();

const sheetDetails = ref({});

const getProOrderDetails = async (id) => {
  const res = await detailsProductionMaterialRequisitionWithIdApi(id);
  sheetDetails.value = res.data;
  sheetDetails.value.dataStatus = String(res.data.dataStatus);
  sheetDetails.value.productionOrganizationId = String(
    res.data.productionOrganizationId
  );
  sheetDetails.value.matterList?.forEach((item) => {
    item.stockOrganizationId = String(item.stockOrganizationId);
    item.isOriginal = true;
  });
  tableList.value = res.data.matterList;
  documentInfoCreate(res.data);
};
getProOrderDetails(route.params.id);

const tableList = ref([]);

const basicFormRef = ref();

/** 制单信息 */
const documentList = ref([]);
const documentInfoCreate = (details) => {
  let list = [];
  // 制单人
  let cteateInfo = {
    titleTop: "制单人",
    infoTop: details?.createName,
    titleBottom: "创建时间",
    infoBottom: details?.createTime,
  };
  list.push(cteateInfo);

  // 修改人
  let updateInfo = {
    titleTop: "修改人",
    infoTop: details?.updateName,
    titleBottom: "修改时间",
    infoBottom: details?.updateTime,
  };
  list.push(updateInfo);

  // 审核人
  let checkInfo = {
    titleTop: "审核人",
    infoTop: details?.checkName,
    titleBottom: "审核时间",
    infoBottom: details?.checkTime,
  };
  list.push(checkInfo);
  documentList.value = list;
  console.log(documentList.value);
};
documentInfoCreate();

/** 返回 */
const backAction = () => {
  router.go(-1);
};
</script>
